/*
 * @Author: Gaolingqing
 * @Date: 2020-12-29 15:28:09
 * @Last Modified by: TGking
 * @Last Modified time: 2021-01-09 16:13:19
 */
//配置axios
//导出
import axios from 'axios';
import qs from 'qs';
// axios.defaults.baseURL = 'http://47.93.206.13:5588';
axios.defaults.baseURL = 'http://106.15.205.160:8001';
// sessionStorage.clear();
// sessionStorage.removeItem("token");
axios.defaults.headers.common["Authorization"] = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOiJOZz09Iiwic3ViIjoiYWRtaW4xIiwiaXNzIjoiMDk4ZjZiY2Q0NjIxZDM3M2NhZGU0ZTgzMjYyN2I0ZjYiLCJpYXQiOjE2MTAxNzM5NzIsImF1ZCI6InJlc3RhcGl1c2VyIiwiZXhwIjoxNjEwMzQ2NzcyLCJuYmYiOjE2MTAxNzM5NzJ9.ULR5c2SG2utt_hgqHhLdK4v1HlazhYTqjaIOig6Woa4';
//JWT


//请求拦截器
axios.interceptors.request.use(config => {
    // Do something before request is sent
    // alert(1);
    // console.log(config, '-----');

    // config.headers = {
    //     // accept: "",
    //     ...config.headers,
    //     Authorization: sessionStorage.getItem('token'),

    // }

    if (config.method == 'post' && config.url !== '/user/login') {
        config.data = qs.stringify(config.data);
    }
    return config;
}, error => {
    // Do something with request error

    return Promise.reject(error);
});
//响应拦截器
axios.interceptors.response.use(response => {
    // Do something before response is sent
    // console.log(response, '++++');
    let res = {
        ...response,
        data: response.data.data,
        status: response.data.status,
        statusText: response.data.message,
        timestamp: response.data.timestamp
    }
    return res;
}, error => {
    // Do something with response error
    return Promise.reject(error);
});
//导出
export default axios;